\section{Syntax Summary}
\label{sec:syntax}

% ------------------------------------------------------------------------
{ % the following grammar is enclosed in a TeX group
% ------------------------------------------------------------------------
\newcommand{\Col}[1]{\begin{array}[t]{@{}l@{}} #1 \end{array}}
%
\newcommand{\T}  [1]{\mbox{\verb^#1^}}
\newcommand{\Op} [1]{\makebox[3ex]{\T{#1}}}
\newcommand{\NTa}[1]{\mbox{\small$\langle${#1}$\rangle$}}
\newcommand{\NTb}[2]{\NTa{{\it #1-}#2}}
%
\newcommand{\Meta}[1]{\mbox{\footnotesize\sl #1\/}}
\newcommand{\OR}     {\;|\;}
\newcommand{\STAR}   {\Meta{*}}
\newcommand{\OPT} [1]{\Meta{[}\, #1 \,\Meta{]}}
\newcommand{\PAR} [1]{\Meta{(}\, #1 \,\Meta{)}}
\newcommand{\REPa}[1]{#1 \STAR}
\newcommand{\REPb}[1]{\REPa{\PAR{#1}}}
\newcommand{\REPc}[2]{\PAR{#1 \; \Meta{//} \; \T{,}}\;}
\newcommand{\REPd}[1]{\OPT{#1 \; \Meta{//} \; \T{,}}}
%
\newcommand{\Sep}   {\vspace{0.8ex}}
\newcommand{\La} [2]{\NTa{#1} & \rightarrow & #2 \Sep \\}
\newcommand{\Lb} [3]{\La{#1}
			{\begin{array}[t]{@{}l@{}l@{}} 
			    & #2 \\ #3
			 \end{array}}}
\newcommand{\Lc} [1]{|\; & #1 \\}
\newcommand{\Ld} [2]{\La{#1}{\Col{#2}}}
%
\newcommand{\LsizeA}{\scriptsize}
\newcommand{\LsizeB}{\scriptsize}

\newcommand{\Sym}  [1]{\mbox{\LsizeA#1}}
\newcommand{\LMeta}[1]{\mbox{\LsizeB\it #1\/}}
\newcommand{\LNTa} [1]{\mbox{\LsizeA$\langle${#1}$\rangle$}}
\newcommand{\LOPT} [1]{\LMeta{[}\, #1 \,\LMeta{]}}
\newcommand{\LPAR} [1]{\LMeta{(}\, #1 \,\LMeta{)}}
\newcommand{\LREPb}[1]{\LPAR{#1} \LMeta{*}}

\newcommand{\Legend}{%
   \LsizeA
   \setlength{\arraycolsep}{\tabcolsep}
   $\begin{array}{ll@{\hspace{4\arraycolsep}}ll@{\hspace{4\arraycolsep}}ll}
   \LPAR{\cdots}       	       & \mbox{grouping} 		&
   \T{sym} 	   	       & \mbox{terminal symbol}		&
   \LPAR{\Sym{e$_1$} \; \LMeta{//} \; \Sym{e$_2$}}
      & \LREPb{\Sym{e$_1$} \; \Sym{e$_2$}} \; \Sym{e$_1$} 	 \\
   %
   \LOPT{\cdots}       	       & \mbox{option (zero or one)} 	&
   \LNTa{sym} 	    	       & \mbox{non-terminal symbol} 	&
   \LOPT{\Sym{e$_1$} \; \Meta{//} \; \Sym{e$_2$}}
      & \LOPT{\LREPb{\Sym{e$_1$} \; \Sym{e$_2$}} \; \Sym{e$_1$}} \\
   %
   \Sym{e$_1$} \OR \Sym{e$_2$} & \mbox{alternative} 		&
   \LREPb{\cdots} 	       & \mbox{closure (zero or more)} 	&\\
   \end{array}$}
%
\centering
% ------------------------------------------------------------------------
% Start of grammar
% ------------------------------------------------------------------------

\setlength{\tabcolsep}{\arraycolsep}	% store for \Legend
\setlength{\arraycolsep}{0.6\arraycolsep}
\framebox{$\begin{array}{l@{\hspace{0.3\arraycolsep}}ll}
%
\La{schema}
   {\NTa{imports} 
       \; \T{schema} 
       \; \NTb{schema}{name}
       \; \T{\{} \; \REPa{\NTa{type\_declaration}} \; \T{\}} \; \OPT{\T{;}}}
\La{imports}
   {\OPT{\NTa{schema\_imports}} \; \OPT{\T{with} \; \T{extern} \; \T{;}}}
\Sep
\La{schema\_imports}
   {\T{with} \; \REPc{\NTb{schema}{name}} \; \OPT{\T{;}}}
%
\Sep
\Lb{type\_declaration}
   {\NTa{extern\_declaration}}
   {\Lc{\NTa{enumeration\_declaration}}
    \Lc{\NTa{typedef\_declaration}}
    \Lc{\NTa{union\_declaration}}
    \Lc{\NTa{class\_declaration}}}
\Sep
\La{extern\_declaration}
   {\T{extern} \; \NTb{type}{name} 
	       \; \OPT{\T{(} \, \NTa{number} \, \T{)}} \; \T{;}}
\Sep
\La{enumeration\_declaration}
   {\T{enum} \; \NTb{type}{name} 
	     \; \T{\{} \; \REPc{\NTb{literal}{name}} \; \T{\}} \; \OPT{\T{;}}}
\Sep
\Lb{typedef\_declaration}
   {\T{typedef} \; \NTa{type\_name} \; \NTb{type}{name} \; \T{;}}
   {\Lc{\T{typedef} \; \NTa{generic\_instantiation} \; \T{;}}} 
%
\Lb{type\_name}
   {\NTb{type}{name}}
   {\Lc{\NTa{generic\_instantiation}}}
\Sep
\La{generic\_instantiation}
   {\NTb{generic\_class}{name} 
       \; \T{<} \; \REPc{\NTa{type\_name}} \; \T{>}}
%
\Sep
\La{union\_declaration}
   {\T{union} \; \NTb{type}{name} 
	      \; \T{\{} \; \REPc{\NTa{type\_name}} \; \T{\}} \; \OPT{\T{;}}}
%
\La{class\_declaration}
   {\T{class} \; \NTb{type}{name} \; \NTa{class\_body} \; \OPT{\T{;}}}
\Ld{class\_body}
   {\OPT{\T{<} \; \REPc{\NTa{generic\_parameter\_specification}} \; \T{>}} \\
    \OPT{\NTb{create}{parameters}} \\
    \OPT{\T{:} \; \NTa{super\_classes}} \\
    \T{\{} \; \Meta{(}
    	      \Col{ \\ \OR \\ \OR}
              \Col{\NTa{friend\_specification} \\
    	      	   \NTa{method\_kind\_specification}  \\
    	      	   \NTa{method\_declaration} \;\; \Meta{)}\STAR}\\
    \T{\}}}
\Sep
\La{generic\_parameter\_specification}
   {\NTb{type}{name} \; \OPT{\T{:} \; \NTb{superclass}{type\_name}}}
%
\La{super\_classes}
   {\REPc{\NTa{class\_initialization}}}
\Sep
\La{class\_initialization}
   {\NTb{class}{type\_name} \; \OPT{\T{(} \; \REPd{\NTa{expression}} \; \T{)}}}
\Sep
%
\La{friend\_specification}
   {\T{friend} \; \T{class} \; \NTb{class}{type\_name} \; \T{;}}
%
\La{method\_kind\_specification}
   {\NTa{method\_kind\_specifier}
    \; \OPT{\T{,} \; \NTa{method\_kind\_specifier} \; \T{set}} \; \T{:}}
\Sep
\La{method\_kind\_specifier}
   {\T{public} \; \OR \; \T{protected} \; \OR \T{private}}
\Lb{method\_declaration}
   {\NTa{component\_declaration}}
   {\Lc{\NTa{function\_method}}}
%
\end{array}$}
%
\pagebreak
\vspace*{1cm}
\framebox{$\begin{array}{l@{\hspace{0.3\arraycolsep}}ll}
\Lb{component\_declaration}
   {\NTa{static\_component}}
   {\Lc{\NTa{non-static\_component}}}
\La{static\_component}
   {\T{static} \; \NTa{type\_name} \; \REPc{\NTb{component}{name}} \; \T{;}}
\La{non-static\_component}
   {\NTa{component\_kind} \; \NTa{type\_name}
    \; \REPc{\NTa{component\_specification}} \; \T{;}}
\La{component\_kind}
   {\OPT{\T{definite}} \; \OPT{\T{local} \,\OR\, \NTa{value\_specifier}}}
\La{value\_specifier}
   {\T{!}}
\Sep
\La{component\_specification}
   {\NTb{component}{name} \; \OPT{\T{=} \; \NTa{expression}}}
%
\La{function\_method}
   {\OPT{\NTa{function\_kind}}
   	\; \NTb{result}{type\_name} 
	\; \NTa{function\_name} \; \NTa{parameters} \; \T{;}}
\La{function\_kind}
   {\T{static}\,\OR\,\T{definite}\,\OR\,\T{abstract}}
\Lb{function\_name}
   {\NTb{function}{name}}
   {\Lc{\T{operator} \; \NTa{operator\_symbol}}}
\Lb{operator\_symbol}
   {\Op{*}  \OR \Op{/} \OR \Op{\%} \OR \Op{+}  \OR \Op{-} \OR \Op{<<}  \OR
    \Op{>>} \OR \Op{<} \OR \Op{>}  \OR \Op{==} \OR \Op{!=} \OR \Op{<=} \OR
    \Op{>=}}
   {\Lc{\Op{\^{}} \OR \Op{\&}     \OR \Op{|}   \OR \Op{\&\&} \OR \Op{||}  \OR
        \Op{=}    \OR \Op{+=}     \OR \Op{-=}  \OR \Op{*=}   \OR \Op{/=}  \OR
        \Op{\%=}  \OR \Op{\^{ }=} \OR \Op{\&=}}
    \Lc{\Op{|=}   \OR \Op{<<=}    \OR \Op{>>=} \OR \Op{()}   \OR \Op{[\,]}}}
%
\La{parameters}
   {\T{(} \; \REPd{\NTa{parameter}} \; \T{)}}
\Sep
\La{parameter}
   {\NTa{type\_name} \; \OPT{\T{\&}} \; \OPT{\NTb{parameter}{name}}
		 \; \OPT{\T{=} \; \NTa{expression}}}
%
\Lb{expression}
   {\NTa{name}}
   {\Lc{\NTa{number}}
    \Lc{\NTa{name} \; \T{(} \; \REPd{\NTa{expression}} \; \T{)}}}
%
\end{array}$}

{\Legend}
% ------------------------------------------------------------------------
} % end of the TeX group enclosing the SOS grammar
% ------------------------------------------------------------------------

